<?php
namespace lib;

class Session {

    /**
     * 启动session
     * @return bool
     */
    public static function start(){
        return session_start();
    }

    /**
     * 结束session
     * @return bool
     */
    public static function destroy(){
        return session_destroy();
    }

    /**
     * 删除
     * @param $key
     * @return bool
     */
    public static function remove($key){
        unset($_SESSION[$key]);
        return true;
    }

    /**
     * 设置SESSION
     * @param $key
     * @param $val
     * @return bool
     */
    public static function set($key, $val){
        if($val === null || $val === false){
            unset($_SESSION[$key]);
        }else{
            $_SESSION[$key] = $val;
        }
        return true;
    }

    /**
     * 获取SESSION
     * @param bool $key
     * @return bool
     */
    public static function get($key = false){
        return $key ? isset($_SESSION[$key]) ? $_SESSION[$key] : false : $_SESSION;
    }

}